using System.Web.Mvc;
using Microsoft.Practices.Unity;
using Unity.Mvc3;
using BibliotecaVirtual.Controllers;
using BAL.Infrastructure;
using BAL.Interfaces;
using BAL;
using DAL;
using DAL.Models;
using DAL.Interfaces;
using DAL.Infrastructure;

namespace BibliotecaVirtual
{
    public static class Bootstrapper
    {
        public static void Initialise()
        {
            var container = BuildUnityContainer();

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
        }

        private static IUnityContainer BuildUnityContainer()
        {
            var container = new UnityContainer();

            // register all your components with the container here
            // it is NOT necessary to register your controllers

            container.RegisterType<IAutorsService, BALAutors>();
            container.RegisterType<IEditorialsService, BALEditorials>();
            container.RegisterType<IEjemplarsService, BALEjemplars>();
            container.RegisterType<IEstadoEjemplarsService, BALEstadoEjemplars>();
            container.RegisterType<IEstadoPrestamosService, BALEstadoPrestamos>();
            container.RegisterType<IEstadoReservasService, BALEstadoReservas>();
            container.RegisterType<IMaterialsService, BALMaterials>();
            container.RegisterType<IPrestamosService, BALPrestamos>();
            container.RegisterType<IReservacionesService, BALReservaciones>();
            container.RegisterType<ISociosService, BALSocios>();
            container.RegisterType<ITemasMaterialesService, BALTemasMaterials>();
            container.RegisterType<ITemasService, BALTemas>();
            container.RegisterType<ITipoMaterialsService, BALTipoMaterials>();
            container.RegisterType<IUsuarioSocioService, BALUsuarioSocio>();

            container.RegisterType<IRepository<Autors>, Repository<Autors>>();
            container.RegisterType<IRepository<Editorials>, Repository<Editorials>>();
            container.RegisterType<IRepository<Ejemplars>, Repository<Ejemplars>>();
            container.RegisterType<IRepository<EstadoEjemplars>, Repository<EstadoEjemplars>>();
            container.RegisterType<IRepository<EstadoPrestamoes>, Repository<EstadoPrestamoes>>();
            container.RegisterType<IRepository<EstadoReservas>, Repository<EstadoReservas>>();
            container.RegisterType<IRepository<Materials>, Repository<Materials>>();
            container.RegisterType<IRepository<Prestamos>, Repository<Prestamos>>();
            container.RegisterType<IRepository<Reservaciones>, Repository<Reservaciones>>();
            container.RegisterType<IRepository<Socios>, Repository<Socios>>();
            container.RegisterType<IRepository<Temas>, Repository<Temas>>();
            container.RegisterType<IRepository<TemasMateriales>, Repository<TemasMateriales>>();
            container.RegisterType<IRepository<TipoMaterials>, Repository<TipoMaterials>>();
            container.RegisterType<IRepository<UsuarioSocios>, Repository<UsuarioSocios>>();

            container.RegisterType<IContext, ApplicationContext>();
            
            IApplicationContext _context = new DAL.Infrastructure.ApplicationContext(); 
            container.RegisterInstance(_context);


            return container;
        }
    }
}